#pragma once

#include"Common.h"
#include"Visualizer.h"
#include"UnitControlerBase.h"
#include"DroneControler.h"
#include"ProductionManager.h"

class SCHW6 : public AIModule
{
public:
	SCHW6()
		:_started(false)
	{
	}
	virtual void onStart()
	{
		Broodwar->setLocalSpeed(20);
		Broodwar->enableFlag(Flag::UserInput);
		Broodwar->enableFlag(Flag::CompleteMapInformation);

		BWTA::readMap();
		BWTA::analyze();

		Info.Initialize();
		BH.Initialize();
		UCM.Initialize();		

		vector<BuildTask> bt;


		//---//-/-/-/-//-///-/-/-/
		bt.push_back(BuildTask(UnitTypes::Zerg_Drone , 0));
		bt.push_back(BuildTask(UnitTypes::Zerg_Drone , 0));
		bt.push_back(BuildTask(UnitTypes::Zerg_Drone , 0));
		bt.push_back(BuildTask(UnitTypes::Zerg_Drone , 0));
		bt.push_back(BuildTask(UnitTypes::Zerg_Drone , 0));
		bt.push_back(BuildTask(UnitTypes::Zerg_Overlord , 0));
		bt.push_back(BuildTask(UnitTypes::Zerg_Spawning_Pool , 0));
		bt.push_back(BuildTask(UnitTypes::Zerg_Drone , 0));
		bt.push_back(BuildTask(UnitTypes::Zerg_Drone , 0));
		bt.push_back(BuildTask(UnitTypes::Zerg_Hatchery , 1));
		bt.push_back(BuildTask(UnitTypes::Zerg_Zergling , 0));
		bt.push_back(BuildTask(UnitTypes::Zerg_Zergling , 0));
		bt.push_back(BuildTask(UnitTypes::Zerg_Zergling , 0));

		_productionManager.AddTasks(bt);

		_started = true;
	}
	virtual void onFrame()
	{
		if(_started)
		{
			Broodwar->drawTextScreen( 2 , 2 , "Frame count: %d" , Broodwar->getFrameCount());
			Visualizer::Draw();
			UCM.OnFrame();
			_productionManager.OnFrame();
		}
	}
	virtual void onUnitMorph(Unit* unit)
	{
		UCM.OnUnitMorph(unit);
		Info.OnUnitMorph(unit);
	}
	virtual void onUnitCreate(Unit* unit)
	{
		UCM.OnUnitCreate(unit);
	}
	virtual void onSendText(string text)
	{
		if(text == "search")
		{
			_productionManager.Search();
		}
	}
private:
	bool _started;
	ProductionManager _productionManager;
};